home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Workspace / Sced / Source / ScedApp.m < prev    next >
Text File  |  1995-06-12  |  3KB  |  125 lines

  1. #import "ScedApp.h"
  2.  
  3. #define TMP "/tmp"
  4.  
  5. /******** HERE IS WHAT TO DO
  6. ********* choose a suffix for a documenttype (eg fm)
  7. ********* choose a portname for a given application (eg FrameMaker) (or NULL)
  8. ********* find the proper extension
  9. ********* expand the map below 
  10. ********* edit Sced.iconheader (e.g.add: S       fm      Sced    ScedDoc)
  11. ********* make install
  12. ********* cmd-u for the workspacemanager
  13. ********/
  14.  
  15. struct tab {
  16.     char *suffix;
  17.     char *portname;
  18.     char *properExtension;
  19. } map[] = {
  20.         { "fm" , "FrameMaker" , NULL},
  21.         { "EPS" , NULL , "eps" },
  22.     { "fmb" , "FrameMaker", NULL },
  23.     { "cgm" , "IconBuilder" , NULL},
  24.     { "cgmb" , "IconBuilder" , NULL},
  25.         { NULL , NULL, NULL}
  26. };
  27.  
  28.  
  29. @implementation ScedApp
  30.  
  31. int attp(char *text, char *a1, char *a2) {
  32.     NXRunAlertPanel("Sced Error Message", text,"ok",NULL,NULL,a1,a2,NULL);
  33.     return 0;
  34. }
  35.  
  36. -  appDidInit:sender {
  37.     
  38.     [self hide:self];
  39.     return(self);
  40. }
  41.  
  42.  
  43. - (int)openFile:(const char *)fullPath ok:(int *)flag {
  44.  
  45.     char *suffix;
  46.     int i;
  47.         int     msgDelivered, fileOpened; 
  48.         port_t thePort;
  49.         id  mySpeaker;
  50.     char buffer[256];
  51.     *flag=NO;
  52.  
  53.     /* find the suffix */
  54.     if((suffix=rindex(fullPath,'.'))==NULL) {
  55.         return(0);
  56.     }
  57.     suffix++;
  58.  
  59.     /* walk */
  60.     i=0;
  61.     while(map[i].suffix!=NULL) {
  62.         if(strcmp(map[i].suffix,suffix)==0) {
  63.             *flag=YES;
  64.                 mySpeaker = [[Speaker alloc] init]; 
  65.                 if(map[i].portname==NULL) {
  66.                 if(map[i].properExtension==NULL) {
  67.                     attp("Sced can't handle the configuration data for %s",map[i].suffix,"");
  68.                     return(1);
  69.                 }
  70.                 else
  71.                     thePort=NXPortFromName("Workspace", NULL);
  72.             } else
  73.                 thePort = NXPortFromName(map[i].portname, NULL); 
  74.                 if (thePort != PORT_NULL) {
  75.                         [mySpeaker setSendPort:thePort]; 
  76.                         
  77.                 if(map[i].properExtension==NULL) {
  78.                     strcpy(buffer,fullPath);
  79.                     msgDelivered = [mySpeaker openFile:fullPath ok:&fileOpened]; 
  80.                         } else {
  81.                     strcpy(buffer,TMP);
  82.                     strcat(buffer,"/");
  83.                     suffix=rindex(fullPath,'/');
  84.                     if(suffix==NULL) strcat(buffer,fullPath);
  85.                     else strcat(buffer,suffix+1);
  86.                     suffix=rindex(buffer,'.');
  87.                     suffix++;
  88.                     strcpy(suffix,map[i].properExtension);
  89.                     if(symlink(fullPath,buffer)==0) 
  90.                         msgDelivered = [mySpeaker openTempFile:buffer ok:&fileOpened];
  91.                     else
  92.                         msgDelivered = [mySpeaker openFile:fullPath ok:&fileOpened];
  93.                 }
  94.                 if (msgDelivered == 0) {
  95.                                 if (fileOpened == YES) 
  96.                                         fprintf(stderr,"Sced invoced %s for %s with some success\n",map[i].portname,buffer);
  97.                                 else
  98.                                         attp("Sced failed to invoce %s for %s\n",map[i].portname,buffer);
  99.                         }
  100.                         else {
  101.                                     attp("Sced failed to invoce %s for %s\n",map[i].portname,buffer);
  102.                         }
  103.                 }
  104.                 else {
  105.                                 attp("Sced failed to invoce %s for %s\n",map[i].portname,fullPath);
  106.                 }
  107.                 [mySpeaker free];
  108.                 port_deallocate(task_self(), thePort); 
  109.  
  110.             [self hide:self];
  111.             return(0);
  112.         }
  113.         i++;
  114.     }
  115.  
  116.     return(0);
  117. }
  118.  
  119.  
  120. - (BOOL) appAcceptsAnotherFile:sender {
  121.     return(YES);
  122. }
  123.  
  124. @end
  125.